package com.well.module.user.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.well.kernel.service.AbstractService;
import com.well.module.user.entity.User;
import com.well.module.user.mapper.UserMapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;
import tk.mybatis.mapper.entity.Example.Criteria;

import java.util.List;

/**
 * Copyright &copy; Well All rights reserved.
 * Author:Well
 * Date:2017-11-28
 * Description:
 */

@Service
public class UserService extends AbstractService<User>{

    @Autowired
    private UserMapper userMapper;

    public PageInfo<User> selectPageInfo(User user){
        int pageNum=user.getPageNum();
        int pageSize=user.getPageSize();
        /*Example example=new Example(User.class);
        Criteria criteria=example.createCriteria();
        String username=user.getUsername();
        if(StringUtils.isNotEmpty(username)){
            criteria.andLike("username","%"+username+"%");
        }
        String password=user.getPassword();
        if(StringUtils.isNotEmpty(password)){
            criteria.andLike("password","%"+password+"%");
        }*/
        PageHelper.startPage(pageNum,pageSize);
//        List<User> list=userMapper.selectByExample(example);
        List<User> list=userMapper.getUserAndUserInfoList(user);
        PageInfo<User> pageInfo=new PageInfo<>(list);
        return pageInfo;
    }


}
